package com.cxx.purchasecharge.dal.impl;

import javax.persistence.Query;

import org.apache.commons.collections.CollectionUtils;

import com.cxx.purchasecharge.core.model.persistence.GoodsUnit;
import com.cxx.purchasecharge.dal.GoodsUnitDao;
import com.cxx.purchasecharge.dal.common.MyGenericDaoImpl;

public class GoodsUnitDaoImpl extends MyGenericDaoImpl<GoodsUnit, Long> implements GoodsUnitDao {

	public GoodsUnitDaoImpl() {
		super(GoodsUnit.class);
	}

	@Override
	public GoodsUnit findByName(String name) {
		String sql = "select g from GoodsUnit g where g.name=?1";
		Query query = getEntityManager ().createQuery (sql, GoodsUnit.class);
		query.setParameter (1, name);
		return CollectionUtils.isNotEmpty (query.getResultList ()) ? (GoodsUnit)query.getResultList ().get (0) : null;
	}

}
